package com.kingyun.gpsinspection.purificationservice.services.tdm.innerservice.impl;

import com.cqhilink.api.common.utils.UniqueUtil;
import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.EmployeeVo;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.tdm.ProblemCloseMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.tdm.TdmProblemMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.Problem;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.ProblemClose;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.ProblemCloseVo;
import com.kingyun.gpsinspection.purificationservice.facade.service.tdm.ProblemCloseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * Created by sugongche on 2017/5/5.
 */
public class ProblemCloseServiceImpl implements ProblemCloseService {
    @Autowired
    private ProblemCloseMapper problemCloseMapper;
    @Autowired
    private TdmProblemMapper tdmProblemMapper;

    /**
     * 保存问题关闭
     * @param employeeVo
     * @param problemClose
     * @return
     */
    @Override
    public int save(EmployeeVo employeeVo, ProblemClose problemClose) {
        int a = 0;

        Problem problem = new Problem();
        problem.setProblemId(problemClose.getProblemId());
        problem.setStatus((short) 6);
        a += tdmProblemMapper.updateByPrimaryKeySelective(problem);

        problemClose.setProblemCloseId(UniqueUtil.uuid());
        problemClose.setCloseUserId(employeeVo.getEmployeeId());
        problemClose.setCloseTime(new Date());
        a += problemCloseMapper.insert(problemClose);

        return  a;
    }

    /**
     * 根据问题ID查询封装类
     * @param problemId
     * @return
     */
    @Override
    public ProblemCloseVo queryVoByProblemId(String problemId) {
        List<ProblemCloseVo> list = problemCloseMapper.selectByProblemId(problemId);

        if(list != null && list.size()>0){
            return  list.get(0);
        }else{
            return null;
        }
    }
}
